package com.brsya.movie.presenter;

import com.brsya.base.base.BasePresenter;
import com.brsya.base.bean.BaseListBean;
import com.brsya.base.bean.BaseObjectBean;
import com.brsya.base.bean.HomeTabBean;
import com.brsya.base.net.MyObserver;
import com.brsya.base.net.RxScheduler;
import com.brsya.movie.contract.HomeContract;
import com.brsya.movie.model.HomeModel;

import java.util.Map;

/**
 * Created by Brsya
 * CreateDate: 2022/7/5  9:06
 * Description:
 * 首页逻辑层
 */
public class HomePresenter extends BasePresenter<HomeContract.View> implements HomeContract.Presenter {
    private HomeContract.Model model;

    public HomePresenter() {
        model = new HomeModel();
    }

    @Override
    public void getHomeTab() {
        mView.showLoading();

        Map<String, Object> par = getPublicPar();

        model.getHomeTabData(par)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new MyObserver<BaseObjectBean<HomeTabBean>>(mView) {
                    @Override
                    public void success(BaseObjectBean<HomeTabBean> baseBean) {
                        baseBean.handleData(HomeTabBean.class);
                        if (baseBean.getData() == null) {
                            mView.TabDataError();
                            return;
                        }
                        mView.showTabData(baseBean.getData());
                    }
                });

    }
}
